package predicates

import (
	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
	"sigs.k8s.io/controller-runtime/pkg/event"
	"sigs.k8s.io/controller-runtime/pkg/predicate"
)

func ClusterUnPause() predicate.Funcs {
	return predicate.Funcs{
		UpdateFunc: func(e event.UpdateEvent) bool {
			if newObj := e.ObjectNew.(*clusterv1.Cluster); newObj != nil {
				// Only need to trigger a reconcile if the Cluster.Spec.Paused is false
				return !newObj.Spec.Paused
			}
			return false
		},
		CreateFunc: func(e event.CreateEvent) bool {
			if obj := e.Object.(*clusterv1.Cluster); obj != nil {
				return !obj.Spec.Paused
			}
			return false
		},
		DeleteFunc:  func(event.DeleteEvent) bool { return false },
		GenericFunc: func(event.GenericEvent) bool { return false },
	}
}
